import requests

def get_ql_url():
  return "https://explorer.bitquery.io/zh/proxy_graphql"

def get_headers():
  return {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9",
    "content-type": "application/json",
    "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"macOS\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "x-csrf-token": "mPEvQCgF/cB8QoB/Yf+0raKcbM5pohQFqdxZgQimu1T4QJbL+GY8wr3o4w57oNGJ17P/GqonyED7aL1GMW/Icg==",
    "cookie": "_fbp=fb.1.1645509079675.627989847; _gid=GA1.2.1610516586.1645509080; _ga=GA1.1.5988813.1645509080; _ga_J5F4SQLVDZ=GS1.1.1645510693.1.1.1645511889.0; _explorer_session=zLrlUnVTiXpNTjtOkUuQD34ltMFM4vmfkWMZAFKvABK7j25gjuWKjM2F4p24GYP4ycYR6mft3Gu1b6lvcNphNrODWsyIogbCCGgJAn9i1sKxNmxypL8Cr4V3ai1m5t%2BBrrs77%2FZXtO3Ow2wd1PsRddGrIuTutoqGQ3jbEo0fTxUn6kZwFCG7KQZJoP7Pane4zSF687OARGtnhTGYHfHifoSpbeSUoCGz1j0Qta44a6x5shb1SDO1R77suL36O%2Btwh9eJhC2iKwZi67WpkQZWtJIvG4DDCj8xT7k0x%2F0HD%2B4N%2B5mX4K4YNznVELn9VhJFra%2BFoc6Mzgua1O%2FoM8U4HwQ%3D--V6v4HhjdyvTfIKyh--kmOKHjooeFWdEY7OhsNOxA%3D%3D",
    "Referer": "https://explorer.bitquery.io/zh/goerli/txs/transfers?receiver=0x04b3edf2ec6667c3e95e0d19f5e12fcc9234d347&currency=GTH",
    "Referrer-Policy": "strict-origin-when-cross-origin"
  }

def get_ql_str(limit: int, offset: int):
  return '{\"operationName\":null,\"variables\":{\"limit\":' + str(limit) +',\"offset\":'+ str(offset) +',\"network\":\"goerli\",\"address\":\"0x04b3edf2ec6667c3e95e0d19f5e12fcc9234d347\",\"currency\":\"GTH\",\"sender\":\"\",\"from\":\"2022-01-24\",\"till\":\"2022-02-22T23:59:59\",\"dateFormat\":\"%Y-%m-%d\"},\"query\":\"query ($network: EthereumNetwork!, $address: String!, $limit: Int!, $offset: Int!, $currency: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) {\\n  ethereum(network: $network) {\\n    transfers(options: {desc: \\\"block.timestamp.time\\\", limit: $limit, offset: $offset}, date: {since: $from, till: $till}, amount: {gt: 0}, currency: {is: $currency}, receiver: {is: $address}) {\\n      block {\\n        timestamp {\\n          time(format: \\\"%Y-%m-%d %H:%M:%S\\\")\\n          __typename\\n        }\\n        height\\n        __typename\\n      }\\n      address: sender {\\n        address\\n        annotation\\n        __typename\\n      }\\n      currency {\\n        address\\n        symbol\\n        __typename\\n      }\\n      amount\\n      transaction {\\n        hash\\n        __typename\\n      }\\n      external\\n      __typename\\n    }\\n    __typename\\n  }\\n}\\n\"}'

if __name__ == '__main__':
  TOTAL = 14594
  STEP = 1000

  offset = 0
  while offset < TOTAL:
    responce = requests.post(get_ql_url(), headers=get_headers(), data=get_ql_str(STEP, offset))
    transfers = responce.json()['data']['ethereum']['transfers']
    for transfer in transfers:
      print(transfer['transaction']['hash'])
    offset += STEP

  